package com.bwsoft.portal.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.bwsoft.admin.domain.Banner;
import com.bwsoft.admin.domain.News;
import com.bwsoft.admin.domain.valueObject.NewsVO;
import com.bwsoft.api.pojo.ResponsePojo;
import com.bwsoft.util.ValidatorUtil;
import com.google.code.kaptcha.Constants;

public class IndexPageAction extends PortalBaseAction {

	private static Logger LOG = Logger.getLogger(IndexPageAction.class);

	private List<Banner> bannerList;
	private List<NewsVO> newsVOs;
	private String kaptchaReceived;
	private String account;
	private String password;
	private String code;

	public String index() {

		// 得到轮播图List
		bannerList = bannerService.findShowBannerData();
		// 得到新闻集合
		List<News> newsList = newsService.findData(1, 20, "", "", "", "1");
		// 转换VO 对象
		newsVOs = newsService.getVo(newsList);

		return "index";
	}
	
	public String toLogin(){
		return "toLogin";
	}

	public String login() {
		String kaptchaExpected = (String) session.get(Constants.KAPTCHA_SESSION_KEY);
		LOG.info("系统验证吗是："+kaptchaExpected);
		LOG.info("客户端输入的验证码是："+code);
		if (code == null
				|| !code.equalsIgnoreCase(kaptchaExpected)) { // 判断内容是否相同
				responseJson.put("result", "3");
				responseJson.put("msg", "验证码错误！");
				return "mapJsonResult";
		} 
		if(!ValidatorUtil.isMobile(account)&&!ValidatorUtil.isEmail(account)){
			responseJson.put("result", "1");
			responseJson.put("msg", "账号只能为邮箱或手机号！");
			return "mapJsonResult";
		}
		
		ResponsePojo rp=indexPageService.findAccount(account,password);
		responseJson.put("result", rp.getErrcode());
		responseJson.put("msg", rp.getErrmsg());
		responseJson.put("account", rp.getData());
		return "mapJsonResult";
	}
	
	public String logout(){
		session.put("Account",null);
		
		return "logout";
	}
	
	public String gsjs(){
		return "gsjs";
	}
	public String lxwm(){
		return "lxwm";
	}
	public String bgcd(){
		return "bgcd";
	}
	public String zlkz(){
		return "zlkz";
	}

	public List<Banner> getBannerList() {
		return bannerList;
	}

	public void setBannerList(List<Banner> bannerList) {
		this.bannerList = bannerList;
	}

	public List<NewsVO> getNewsVOs() {
		return newsVOs;
	}

	public void setNewsVOs(List<NewsVO> newsVOs) {
		this.newsVOs = newsVOs;
	}

	public String getKaptchaReceived() {
		return kaptchaReceived;
	}

	public void setKaptchaReceived(String kaptchaReceived) {
		this.kaptchaReceived = kaptchaReceived;
	}

	public String getAccount() {
		return account;
	}

	public void setAccount(String account) {
		this.account = account;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	

}
